package cn.ecut.dzy.dao.impl;


import cn.ecut.dzy.dao.OrderDao;
import cn.ecut.dzy.pojo.Order;

import java.util.List;

public class OrderDaoImpl extends BaseDao implements OrderDao {
    @Override
    public int saveOrder(Order order) {
        String sql = "insert into t_order(`order_id`,`create_time`,`price`,`status`,`user_id`) values(?,?,?,?,?)";

        return update(sql,order.getOrderId(),order.getCreateTime(),order.getPrice(),order.getStatus(),order.getUserId());
    }

    @Override
    public List<Order> queryOrders() {
        String sql = "SELECT `order_id` as `orderId`,`create_time` as createtime,price,status,`user_id` as `userId`  FROM t_order";
        return queryForList(Order.class,sql);
    }

    @Override
    public int changeOrderStatus(Order order, String status) {
        String sql = "update t_order set `status`=? where order_id = ?";
        return update(sql,status,order.getOrderId());

    }

    @Override
    public List<Order> queryOrdersByUserId(String userId) {
        String sql = "SELECT `order_id` as `orderId`,`create_time` as createtime,price,status,`user_id` as `userId`  FROM t_order where user_id=?";
        return queryForList(Order.class,sql,userId);
    }

    @Override
    public void updateStatus(String orderId, Integer orderStatus) {
        String sql="update t_order set status = ? where order_id = ?; ";
        update(sql,orderStatus,orderId);
    }


}
